#include <stdio.h>  
#include <time.h>  
#include <math.h>  
  
#define MAX_PRIMES 1000000  
  
int is_prime(int num) {  
    if (num <= 1) {  
        return 0;  
    }  
    for (int i = 2; i <= sqrt(num); i++) {  
        if (num % i == 0) {  
            return 0;  
        }  
    }  
    return 1;  
}  
  
int count_primes(int n) {  
    int count = 0;  
    for (int i = 2; i <= n; i++) {  
        if (is_prime(i)) {  
            count++;  
        }  
    }  
    return count;  
}  
  
int main() {  
    int n = MAX_PRIMES;  
    clock_t start, end;  
    double elapsed_time;  
    srand((unsigned) time(NULL));  // 使用当前时间作为随机数种子  
    int random_number = rand() % n + 1;  // 生成一个随机数  
    printf("找到第 %d 个素数：%d\n", count_primes(random_number), random_number);  
    start = clock();  // 记录起始时间点  
    printf("小于 %d 的素数个数为：%d\n", n, count_primes(n));  
    end = clock();  // 记录结束时间点  
    elapsed_time = ((double) (end - start)) / CLOCKS_PER_SEC;  // 计算时间差，单位为秒  
    printf("执行时间：%.6f seconds\n", elapsed_time);  
    return 0;  
}